package com.zhudeshuai.zhudemolist.widget.BarChart;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;

import com.zhudeshuai.zhudemolist.widget.GraphicalView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhudeshuai
 * @since 16/7/1
 */
public class BarChartView extends GraphicalView {

    private BarChar mBarChar = new BarChar(0, 2000, 5);

    public BarChartView(Context context) {
        this(context, null);
    }

    public BarChartView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        mBarChar.setRectFBg(0, 0, getMeasuredWidth(), getMeasuredHeight());
    }

    private void initView() {
        List<BarChartData> datas = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            BarChartData data = new BarChartData();
            data.mName = "张三" + i;
            data.dataLength = 400 + i * 300;
            datas.add(data);
        }
        setShowData(datas);
    }

    public void setShowData(List<BarChartData> data) {
        mBarChar.setShowData(data);
    }

    @Override
    public void render(Canvas canvas) {
        mBarChar.render(canvas);
    }
}
